<?php


namespace App\Http\Controllers\Documents;

use App\Http\Controllers\common\LMReturn;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use ShowapiRequest;

class CurrentNewsController extends Controller
{
    public function queryNewsClass(Request $request)
    {
        $news_class_list = [
            [
                "channelId" => "5572a109b3cdc86cf39001e0",
                "name" => "财经最新"
            ],
            [
                "channelId" => "5572a109b3cdc86cf39001e1",
                "name" => "理财最新"
            ],
            [
                "channelId" => "5572a109b3cdc86cf39001dc",
                "name" => "台湾最新"
            ],
            [
                "channelId" => "5572a109b3cdc86cf39001dd",
                "name" => "港澳最新"
            ],
            [
                "channelId" => "5572a109b3cdc86cf39001de",
                "name" => "国际最新"
            ],
            [
                "channelId" => "5572a109b3cdc86cf39001df",
                "name" => "军事最新"
            ],
            [
                "channelId" => "5572a109b3cdc86cf39001e2",
                "name" => "宏观经济最新"
            ],
            [
                "channelId" => "5572a109b3cdc86cf39001e3",
                "name" => "互联网最新"
            ],
            [
                "channelId" => "5572a109b3cdc86cf39001e4",
                "name" => "房产最新"
            ],
            [
                "channelId" => "5572a109b3cdc86cf39001e5",
                "name" => "汽车最新"
            ],
            [
                "channelId" => "5572a109b3cdc86cf39001e6",
                "name" => "体育最新"
            ],
            [
                "channelId" => "5572a10ab3cdc86cf39001e7",
                "name" => "国际足球最新"
            ],
            [
                "channelId" => "5572a10ab3cdc86cf39001e8",
                "name" => "国内足球最新"
            ],
            [
                "channelId" => "5572a10ab3cdc86cf39001e9",
                "name" => "CBA最新"
            ],
            [
                "channelId" => "5572a10ab3cdc86cf39001ea",
                "name" => "综合体育最新"
            ],
            [
                "channelId" => "5572a10ab3cdc86cf39001eb",
                "name" => "娱乐最新"
            ],
            [
                "channelId" => "5572a10ab3cdc86cf39001ed",
                "name" => "电影最新"
            ],
            [
                "channelId" => "5572a10ab3cdc86cf39001ee",
                "name" => "游戏最新"
            ],
            [
                "channelId" => "5572a10ab3cdc86cf39001ef",
                "name" => "教育最新"
            ],
            [
                "channelId" => "5572a10ab3cdc86cf39001f0",
                "name" => "女人最新"
            ],
            [
                "channelId" => "5572a10ab3cdc86cf39001f1",
                "name" => "美容护肤最新"
            ],
            [
                "channelId" => "5572a10ab3cdc86cf39001f2",
                "name" => "情感两性最新"
            ],
            [
                "channelId" => "5572a10ab3cdc86cf39001f3",
                "name" => "健康养生最新"
            ],
            [
                "channelId" => "5572a10ab3cdc86cf39001f4",
                "name" => "科技最新"
            ],
            [
                "channelId" => "5572a10bb3cdc86cf39001f5",
                "name" => "数码最新"
            ],
            [
                "channelId" => "5572a10bb3cdc86cf39001f6",
                "name" => "电脑最新"
            ],
            [
                "channelId" => "5572a10bb3cdc86cf39001f7",
                "name" => "科普最新"
            ],
            [
                "channelId" => "5572a10bb3cdc86cf39001f8",
                "name" => "社会最新"
            ],
            [
                "channelId" => "57463656a44a13cf",
                "name" => "旅游最新"
            ],
            [
                "channelId" => "61b6c4326de57a0ac09d7e08",
                "name" => "家政最新"
            ],
            [
                "channelId" => "61b6c3e26de57a0ac09d7e07",
                "name" => "育儿最新"
            ],
            [
                "channelId" => "9a15d3d4b5cab17f34e6d7976b1b1f30",
                "name" => "电商最新"
            ],
            [
                "channelId" => "5b4fe11ec1239b0805568da6e90fd875",
                "name" => "物流最新"
            ],
            [
                "channelId" => "3f4794412eaa17ed",
                "name" => "创业最新"
            ],
        ];
        return LMReturn::Success($news_class_list);
    }
    public function queryNewsList(Request $request)
    {
        // try {
        $all = $request->all();
        $title = $all['title'] ?? '';
        $channelId = $all['channelId'] ?? '5572a109b3cdc86cf39001e0';
        $page = $all['page'] ?? 1;
        $size = $all['size'] ?? 15;
        $id = $all['id'] ?? '';
        // } catch (\Throwable $th) {
        //     return LMReturn::Error('传参错误，请检查传参', 'CNCQNL2');
        // }
        // try {
        //更多说明请访问仓库地址：https://github.com/showapi-public/showapi_sdk_php
        //支持php5.5以上版本

        include_once 'showapi_sdk_php/Util/Autoloader.php'; //包含sdk中的自动导入工具类
        $url = "http://route.showapi.com/109-35";
        $METHOD = "POST";
        $showapi_appid = "374892"; //替换此值,你可以在这里找到 https://www.showapi.com/console#/myApp
        $showapi_sign = "c3106c8606b04f28976b4fe5cf39a0a8"; //替换此值,你可以在这里找到 https://www.showapi.com/console#/myApp

        $req = new ShowapiRequest($url, $showapi_appid, $showapi_sign);
        $req->addTextPara("channelId", $channelId);
        $req->addTextPara("channelName", "");
        $req->addTextPara("title", $title);
        $req->addTextPara("page", $page);
        $req->addTextPara("needContent", "0");
        $req->addTextPara("needAllList", "0");
        $req->addTextPara("maxResult", $size);
        if ($id != '') {
            $req->addTextPara("id", $id);
            $req->addTextPara("needHtml", "1");
        }
        $response = $req->post();
        $response = $response->getContent();
        $response = json_decode($response);
        return $response;
        return LMReturn::Success($response->showapi_res_body->pagebean);
        // } catch (\Throwable $th) {
        //     return LMReturn::Error('传参错误，请检查传参', 'CNCQNL1');
        // }
    }
}
